﻿/*****************************************介绍*****************************************
 * 作者：24531
 * 创建时间：2025-08-27 22:46:54
 * 功能：Toggle开关图片控制
**************************************************************************************/

using System;
using UnityEngine;
using UnityEngine.UI;

public class ToggleStateCtrl : MonoBehaviour
{
    private Toggle m_Toggle;
    private GameObject m_On;
    private GameObject m_Off;

    private void Awake()
    {
        m_Toggle = GetComponent<Toggle>();
        m_On = transform.Find("On").gameObject;
        m_Off = transform.Find("Off").gameObject;
        m_Toggle.onValueChanged.AddListener(OnValueChanged);
    }

    private void OnValueChanged(bool isOn)
    {
        m_On.SetActive(isOn);
        m_Off.SetActive(!isOn);
    }

    private void OnEnable()
    {
        OnValueChanged(m_Toggle.isOn);
    }
}